//引入字体图标样式
require("../../assets/fonts/iconfont.css");
//引入swiper插件
require("../../libs/swiper/swiper-bundle.min.css");
require("../../libs/swiper/swiper-bundle.min.js");
const axios = require("../../assets/js/axios.js");
//引入自定义js
let obj = require("../../assets/js/my.js");
//引入自己的样式
require("./index.less");
let $ = obj.$;
let tab = obj.tab;
let addTabs = obj.addTabs;
document.addEventListener("DOMContentLoaded", async function () {
	let swiper = new Swiper(".swiper-container", {
		slidesPerView: 2,
		spaceBetween: 30,
		centeredSlides: true,
		speed: 800,
		loop: true,
		autoplay: {
			delay: 1500,
			disableOnInteraction: false,
			pauseOnMouseEnter: true,
		},
		pagination: {
			el: ".swiper-pagination",
			clickable: true,
		},
	});
	tab("#tab a", "active");
	addTabs("index");
	let res = await axios.get("/api/user/info");
	if (res.data.errno === 0) {
		$("#rankNum").textContent = res.data.data.ranking;
		$("#badgeNum").textContent = res.data.data.badges;
		$("#clockNum").textContent = res.data.data.clockCount;
	}
	//打卡的判断
	function render() {
		axios.get("/api/user/clockInInfo").then((res) => {
			if (res.data.data.isClockIn) {
				$("#clockNum").textContent = res.data.data.clockCount;
				$("#clockBtn").disabled = true;
				$("#clockBtn").textContent = "已打卡";
				$("#clockBtn").style = `background-color:#777;`;
			}
		});
	}
	render();
	//打卡
	$("#clockBtn").addEventListener("click", function () {
		axios.post("/api/user/clockIn").then((res) => {
			if (res.data.errno === 0) {
				render();
			}
		});
	});
	//课程训练跳转
	$(".coure").addEventListener("click", function () {
		location.href = "./sports_course.html";
	});
	// 户外跑步
	$(".run").addEventListener("click", function () {
		location.href = "./countdown.html";
	});
});
